package com.erp.erp_mask.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.erp.erp_mask.mapper.TProentrepotMapper;
import com.erp.erp_mask.pojo.TProcess;
import com.erp.erp_mask.pojo.TProentrepot;
import com.erp.erp_mask.pojo.TPurchase;
import com.erp.erp_mask.service.TProentrepotService;
import com.erp.erp_mask.vo.Result;
import jakarta.annotation.Resource;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/pro")
public class TProentrepotController {

    @Resource
    private TProentrepotService tProentrepotService;
    @Resource
    private TProentrepotMapper tProentrepotMapper;

    @GetMapping("/put")
    public ModelAndView index(){
        return new ModelAndView("/pro/proentrepot");
    }


    @GetMapping("/searchpot")
    public Result search(String startdate,String overdate,String proname,Long pageNo, Long pageSize){
        LambdaQueryWrapper<TProentrepot> wrapper = Wrappers.lambdaQuery();
        if (StringUtils.hasLength(startdate) && StringUtils.hasLength(overdate)) {
            wrapper.between(TProentrepot::getDeliveryDate,startdate,overdate);
        }else if(StringUtils.hasLength(proname)){
            wrapper.like(TProentrepot::getProName,proname);
        }
        return Result.success(tProentrepotService.search(pageNo,pageSize,wrapper));
    }
    @PostMapping("/insertdata")
    public Result insertdatalist(@RequestBody TProcess tProcess){
        System.out.println(tProcess);
        try{
            tProentrepotMapper.insertdatalist(tProcess);
            return Result.success("审核通过,已入库!");
        }catch (Exception e){
            return Result.fail("审核未通过,入库失败!");
        }
    }
}
